technical_minecraftfandomcom-20200214-history
Lightning
should at some point in time be merged with [http://technical-minecraft.wikia.com/wiki/LightningBolt LightningBolt since it´s kind of the same page] Lightning The LightningBolt class only inherits code from the Entity and the EntityWeatherEffect -class. Since the EntityWeatherEffect class has almost literally no code, Lightnings can be thought of inheriting code from the Entity class only. Whether this is worth mentioning is discussable. In general it lights the block it strikes on fire then deals 5 fire damage to any entity in a 63 block cube centered 3 blocks above the block it strikes then lights those mobs on fire. How Does Lightning Affect Mobs? Spawning and usage Lightning naturally spawns in game during a Thunderstorm. It can also be spawned in via commands with /summon Lightning ~ ~ ~ This can be used for a plethora of things, mainly used for visual effects or weapons in custom maps. Effects on mobs Because it only deals fire damage it doesn't harm nether mobs at all, however some mobs have interesting effects: * Creepers - Turn "charged" but still take damage from the first and repetitive strikes. * Ender Dragon - Does not take damage(no video evidence in Xisumavoid's video). * Endermen - Do teleport after taking damage. * Pigs - Turned into sword-less Zombie Pigmen.pre1.7 Turn into normal Zombie Pigman 1.7+ * Villager - Turns into a Witch. before 1.8 * Witch - Takes damage, but uses a fire-resistance potion and becomes immune to being lit on fire and repetitive strikes. * Wither Skeleton - Do not take damage but appear to be set alight (more details please). * Wither - Does not take damage. Interpretation of the Code of the LightningBolt Class When a lightning spawns, it will set a variable called boltLivingTime to a random value between 1 and 4. A variable called lightningState will be set to 2. It will then check, if it exists serverside and not just clientside, whether the gamerule "doFireTick" is true, whether the difficulty is normal or hard and whether a 10x10 area around the spot, where the lightning spawned, is loaded. If that should all be the case, then it will do the following things: The lightning will remember the Position of the Block it is in, and call it var8. If var8 is an air block and fire can be placed on the block below, then the air block will be replaced with fire. It will repeat 4 times the following process: 3 random numbers (one for each axis) between -1 and 1 will be added to the x, y and z coordinates of var8. If var8 is an air block and fire can be placed on the block below, then the air block will be replaced with fire. Interpretation: 1 Fire block can spread up to 4 blocks away on each axis from the position of the lightning entity, however the fire is generally more likely to generate nearby the lightning entity. After a lightning has been generated, it will do the following things every tick: First the Lightning will do everything entities do in general when they´re updated. After doing general entity stuff, the following things happen: If lightningState is 2, then some sound effects will be played. (Thunder and explosion) On every update lightningState will be reduced by 1. If lightningState is less than 0, then it will do the following things: If boltLivingTime is 0, the Lightning will die. If the lightningState is less than a random number between -9 and 0, then boltLivingTime will be reduced by 1, lightningState will be set to 1, the Lightning will randomly change the way it looks, and the lightning will again try to place a fire block at the position of the Lightning entity, using similar checks as the ones used, when a Lightning spawns. If the lightningState is greater than 0 then it will do the following things: If the lightning acutally exists serverside, it will search for entities in a 6x12x6 cube, so that the Lightning entity is at the center of the lower half of the cube. It will then tell all entities inside that cube, except the Lightning itself (technically it´s also inside that cube), that they´ve been struck by lightning. General Behaviour of entities in every tick, using the example of a Lightning. (section is moving to the entity page, it is being retained so it is not lost while the generalized version is checked.) First of all, if an entity is riding the lightning, and that entity is dead, the lightning will stop being ridden by that entity. Then it updates the distance the lightning walked in its lifetime and update its position. It will also update its rotation and where the Lightning is looking. Then it will check, whether the Lightning is inside a Portal, whether the world allows traveling to other dimensions, whether the Lightning is not ridden by any entity, and whether the Lightning has been in the portal long enough to be teleported through the portal. (It might be possible to get a Lightning through an End Portal) If that should ever be the case for any Lightning, that Lightning would be teleported into the Nether. If the Lightning is not inside a portal, its portal timer will be reduced by 4 if it´s greater than 0, and set to 0 if it´s smaller than 0. The portal cooldown will also be reduced by 1. Then the game will check, whether the Lightning is sprinting and is not in water. If that´s true, then it will spawn some particles on the ground below the lightning, with the texture of the blocks the Lightning is sprinting on top. Next on the list is a method to handle water movement: If the Lightning would touch a water block, if it fell down 0.4 blocks (this needs to be verified), but is currently not in water, and hasn´t been updated in this tick yet, then it will make some splash sounds and with a volume depending on the downwards motion of the lightning. It will also spawn some Water Bubble Particles. (It might actually be possible to create water bubbles using a Lightning) Generally if a Lightning is in Water, its fall distance will get reset, and if the Lightning is burning, the fire will be extinguished. If the Lightning does not exist serverside, but only clientside it will also be extinguished. If it should exist serverside and is on fire, the game will check, whether the Lightning is immune to fire. Interestingly enough whether Lightnings are immune to fire is stored in a boolean value, Lightnings never change that value, and the default value for booleans in java is false. So Lightnings are not immune to fire. Therefore the Lightning will get 1 damage from fire every 20 ticks, and the time the Lightning remains on fire will be reduced by one every tick. Next the Lightning will check, whether it would be in lava, if the hitbox is expanded by a little bit (nobody cares about this not being more exact). If it touches the lava, it the Lightning will get 4 damage from lava and will be set on fire for 15 ticks, because Lightnings are not immnure to fire. Additionally the fall distance will be multiplied by 0.5 in every tick the lava is being touched. (For Lightnings it might be possible to get them burning using lava) Next, if the y-coordinate of the Lightning is less than -64, then the Lightning will die. And all that stuff is done with every entity every tick, even with Lightnings. Videos This is an useful video explaining some other properties of Lightning. Category:Entities